Phase 6c: Sync Service β Implementation Plan
TODO
phase6/sync-service β DataPact sync service
Scope
cmmc/services/sync_service.pyβ sync assessment practices with DataPact compliance datatests/test_sync_service.pyβ tests with mocked DataPactClient
Design
Functions
sync_practice(db, assessment_id, practice_id, client?)β SyncResult- Find the assessment practice + its mapped contract(s)
- Call
DataPactClient.get_contract_compliance(contract_id)for each mapping - Update
assessment_practice.datapact_sync_statusanddatapact_sync_at - Log to
DataPactSyncLog(success or error) -
Returns a result dict with status and any error
-
sync_assessment(db, assessment_id, client?)β list[SyncResult] - Get all assessment practices with mappings
- Call
sync_practice()for each - Handle partial failures: one practice failing doesn't stop others
- Returns list of results (some may be errors)
Client Resolution
- Look up
Organization.datapact_api_url/datapact_api_keyfor the assessment's org - Fall back to global config defaults if org fields are null
- Accept optional
clientparameter for testing
Error Handling
- DataPact errors (auth, timeout, rate limit) β logged as error, practice marked
"error" - Missing mapping β skip practice (no sync needed)
- Partial failure β continue syncing remaining practices
Files
| File | Change |
|---|---|
cmmc/services/sync_service.py |
New β service |
tests/test_sync_service.py |
New β tests |